import { publicIpv4 } from "public-ip";

// import { logError } from "./hooks/useLog.js";
import { send } from "./hooks/useEmail.js";
import { loop } from "./hooks/useLoop.js";
import { useIp } from "./hooks/useIp.js";

const IP = useIp();

IP.onChange((ip) => {
  console.log("🚀 ~ ip 改变了，发送邮件:", ip);
  send(ip);
});

async function checkIp() {
  console.log("开始获取IPv4地址");
  const ipv4 = await publicIpv4();
  console.log("🚀 ~ 设置ipv4地址:", ipv4);
  IP.setIp(ipv4);
}

function main() {
  loop(checkIp, 5 * 60 * 1000);
}

main();
